package com.tianji.aigc.entity;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.tianji.aigc.memory.MessageUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.ai.chat.messages.Message;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * @author zy
 * @date 2025/8/10 14:34
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("SPRING_AI_CHAT_MEMORY")
public class ChatMessageMysql implements Serializable {

    @TableId(type = IdType.ASSIGN_ID)
    private Long id;

    private String conversationId;

    private String content;

    private String type;

    private LocalDateTime timestamp;

    public static ChatMessageMysql fromMessage(String conversationId, Message message) {
        return ChatMessageMysql.builder()
                .conversationId(conversationId)
                .content(MessageUtil.toJson(message))
                .type(message.getMessageType().name())
                .timestamp(LocalDateTime.now())
                .build();
    }
}
